<script language="javascript">
	function delData() {
		var obj = document.getElementsByName('txtDel[]');
		for(i = 0; i < obj.length; i++) {
			if(obj[i].checked) {
				if(document.getElementsByName('comment[]')[i].value == "") {
					document.getElementsByName('comment[]')[i].focus();
					alert('กรุณากรอกหมายเหตุค่ะ');
					return;
				}
			}
		}
		var frm = document.forms["myForm"];
		frm.action = "<?=site_url()?>Matching/reject";
		frm.submit();
	}
	function validate() {
		var obj = document.getElementsByName('txtDel[]');
		for(i = 0; i < obj.length; i++) {
			if(obj[i].checked) {
				if(document.getElementsByName('comment[]')[i].value == "") {
					document.getElementsByName('comment[]')[i].focus();
					alert('กรุณากรอกหมายเหตุค่ะ');
					return;
				}
			}
		}
		var frm = document.forms["myForm"];
		frm.action = "<?=site_url()?>Matching/confirm";
		frm.submit();
	}
</script>
<div id="mainContent">

<form  name="myForm" id="myForm" method="post" action="<?=site_url()?>Matching/confirm">
<table width="1000px" border="0" cellspacing="0" cellpadding="0" align="center" >
	<tr align="center">
    	<td> <h2>รายการจับคู่ครูกับนักเรียน</h2><hr/> 
    	</td>
    </tr>
	<tr style="height:10px;">
    	<td>&nbsp;</td>
    </tr>
    <tr >
    	<td><div align="center">
    	  <input name="Submit" type="button" value="ยืนยันการจับคู่" onclick="validate();"/>
    	  <input name="Submit" type="button" value="ยกเลิกการจับคู่" onclick="delData();" />
  	  </div></td>
    </tr>
    <tr style="height:10px;">
    	<td></td>
    </tr>
	<tr>
		<td align="center">          
                  <table width="95%" border="0" cellspacing="2px" cellpadding="0">
                      <tr bgcolor="#000099">
                        <td width="40px">&nbsp;</td>
                        <td width="85px"><div align="center" style="color:#FFFFFF; font-weight:bold;">วันที่ครูเลือกนักเรียน</div></td>
                        <td><div align="center" style="color:#FFFFFF; font-weight:bold;">ชื่อติวเตอร์</div></td>
                        <td><div align="center" style="color:#FFFFFF; font-weight:bold;">ชื่อนักเรียน</div></td>
                        <td><div align="center" style="color:#FFFFFF; font-weight:bold;">วิชาที่จะสอน</div></td>
                        <td width="45"><div align="center" style="color:#FFFFFF; font-weight:bold;">ชั้น</div></td>
                        <td><div align="center" style="color:#FFFFFF; font-weight:bold;">เวลาที่จะสอน</div></td>
                        <td><div align="center" style="color:#FFFFFF; font-weight:bold;">วัน</div></td>
                        <td><div align="center" style="color:#FFFFFF; font-weight:bold;">เขตที่สอน</div></td>
                        <td><div align="center" style="color:#FFFFFF; font-weight:bold;">หมายเหตุ</div></td>
                      </tr>
                      <?php  $monthTh = array("","ม.ค.","ก.พ. ","มี.ค.","เม.ย.","พ.ค.","มิ.ย.","ก.ค.","ส.ค.","ก.ย.","ต.ค.","พ.ย.","ธ.ค.");
                      		$i = 1;
							foreach ($selected_stu as $row) {
								echo '<tr align="left"';
								if($i % 2 == 0) {
									echo ' bgColor=#c6e2ff ';
								}
								
								echo '>';
		                        echo '<td align="center"><input type="checkbox" name="txtDel[]" value="'. $row->student_id .','.$row->maching_id.','.$i.'"/></td>';
		                        echo '<td align="center">' . strftime("%d",strtotime($row->maching_date)) . ' ' . $monthTh[ (int) strftime("%m",strtotime($row->maching_date))]. '</td>';
		                        echo '<td>' . $row->first_name_th . ' ' . $row->last_name_th . '</td>';
		                        echo '<td>' . $row->first_name . ' ' . $row->last_name . '</td>';
		                        echo '<td>'. $row->subject;
		                        echo '</td>';
		                        echo '<td>' . $row->current_class . '</td>';
		                        echo '<td>' . $row->time . '</td>';
		                        echo '<td>' . $row->dayy . '</td>';
		                        echo '<td>' . $row->study_add_distinct. ' ' .$row->study_add_area . '</td>';
		                        echo '<td><textarea name="comment[]" >';
		                        if(isset($row->match_note)) 
		                        	echo $row->match_note;
		                        echo '</textarea></td>';
		                      	echo '</tr>';
		                      	$i++;
							}
                      ?>
                  <tr style="height: 10px;">
                    <td align="right"></td>
                    <td align="left"></td>
                  </tr>
              </table>
		</td>
	</tr>
	<tr>
    	<td align="center"><?php if(isset($paging)) echo $paging;?></td>
    </tr>
    <tr style="height:10px;">
    	<td></td>
    </tr>
</table>
<input type="hidden" name="txtId" id="txtId" />
</form>
</div>
<script type="text/javascript">
function toBlack(obj) {
	obj.src = '<?=base_url()?>images/detail_b.png';
}
function toColor(obj) {
	obj.src = '<?=base_url()?>images/detail.png';
}
function setID(obj) {
	document.getElementById('txtId').value = obj.value;
	var frm = document.forms["myForm"];
	frm.action = "<?=site_url()?>TutorInfo/detail/"+obj.value;
	frm.submit();
}
</script>